

// 将图片链接下载到本地缓存
// 传参：图片远程链接url
// 返回：图片本地缓存路径(http://store/xxxxx.xxx)

function mapCacheUrl(url) {
	let key = `imgcache_${url}`;
	let cache_url = wx.getStorageSync(key);
	if(cache_url){
		return cache_url;
	}
	wx.downloadFile({
		url: url,
		success: function(res) {
			if (res.statusCode === 200) {
				const fs = wx.getFileSystemManager()
				fs.saveFile({
					tempFilePath: res.tempFilePath,
					success(res){
						wx.setStorage({
							key,
							data:res.savedFilePath
						})
					}
				});
				
			}
		}
	});
	return url;
}

export default {
	mapCacheUrl
}